package test.math;

import java.math.BigInteger;

public class Lesson1_1 {

    public static void main(String[] args) {
        System.out.println(decimalToBinary(12));

        System.out.println(binaryToDecimal("110011"));

        int a = 53;
        String b  = "110101";

        System.out.printf("数字 %d 的二进制是 %s\n", a, decimalToBinary(a));
        System.out.printf("数字 %s 的十进制是 %d\n", b, binaryToDecimal(b));
    }

    /**
     * 10进制 --> 2进制
     * @param decimalSource
     * @return
     */
    public static  String decimalToBinary(int decimalSource) {
        BigInteger bigInteger = new BigInteger(String.valueOf(decimalSource));
        return bigInteger.toString(2);
    }

    /**
     * 2进制 --> 10 进制
     * @param binarySource
     * @return
     */
    public static int binaryToDecimal(String binarySource) {
        BigInteger bigInteger = new BigInteger(binarySource, 2);
        return Integer.parseInt(bigInteger.toString());
    }

}
